package org.rsbot.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Collection;
import javax.swing.SwingUtilities;
import org.rsbot.bot.Bot;

public class BotHome
{
  private static final Font FONT = new Font("Helvetica", 1, 13);
  private int width;
  private int height;
  private Bot[] bots = new Bot[0];

  public void setBots(Collection<Bot> paramCollection) {
    SwingUtilities.invokeLater(new Runnable(paramCollection)
    {
      public void run() {
        BotHome.access$002(BotHome.this, (Bot[])this.val$col.toArray(new Bot[this.val$col.size()]));
      } } );
  }

  public void setSize(int paramInt1, int paramInt2) {
    this.width = paramInt1;
    this.height = paramInt2;
  }

  public void paint(Graphics paramGraphics)
  {
    paramGraphics.setColor(Color.black);
    paramGraphics.fillRect(0, 0, this.width, this.height);
    int i = Math.min(this.bots.length, 6);
    if (i == 1) {
      draw(paramGraphics, 0, 0, 0, this.width, this.height);
    } else if (i == 2) {
      draw(paramGraphics, 0, 0, 0, this.width, this.height / 2);
      draw(paramGraphics, 1, 0, this.height / 2, this.width, this.height / 2);
    } else if (i == 3) {
      draw(paramGraphics, 0, 0, 0, this.width / 2, this.height / 2);
      draw(paramGraphics, 1, this.width / 2, 0, this.width / 2, this.height / 2);
      draw(paramGraphics, 2, 0, this.height / 2, this.width, this.height / 2);
    } else if (i == 4) {
      draw(paramGraphics, 0, 0, 0, this.width / 2, this.height / 2);
      draw(paramGraphics, 1, this.width / 2, 0, this.width / 2, this.height / 2);
      draw(paramGraphics, 2, 0, this.height / 2, this.width / 2, this.height / 2);
      draw(paramGraphics, 3, this.width / 2, this.height / 2, this.width / 2, this.height / 2);
    } else if (i == 5) {
      draw(paramGraphics, 0, 0, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 1, this.width / 3, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 2, this.width * 2 / 3, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 3, 0, this.height / 2, this.width / 2, this.height / 2);
      draw(paramGraphics, 4, this.width / 2, this.height / 2, this.width / 2, this.height / 2);
    } else if (i == 6) {
      draw(paramGraphics, 0, 0, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 1, this.width / 3, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 2, this.width * 2 / 3, 0, this.width / 3, this.height / 2);
      draw(paramGraphics, 3, 0, this.height / 2, this.width / 3, this.height / 2);
      draw(paramGraphics, 4, this.width / 3, this.height / 2, this.width / 3, this.height / 2);
      draw(paramGraphics, 5, this.width * 2 / 3, this.height / 2, this.width / 3, this.height / 2);
    } else {
      return;
    }
    FontMetrics localFontMetrics = paramGraphics.getFontMetrics(FONT);
    paramGraphics.setColor(new Color(0, 0, 0, 170));
    paramGraphics.fillRect(0, this.height - 30, this.width, 30);
    paramGraphics.setColor(Color.white);
    paramGraphics.drawString(new StringBuilder().append("Spectating ").append(this.bots.length == 1 ? "1 bot." : new StringBuilder().append(this.bots.length).append(" bots.").toString()).toString(), 5, this.height + localFontMetrics.getDescent() - 14);
  }

  public void draw(Graphics paramGraphics, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5) {
    BufferedImage localBufferedImage = this.bots[paramInt1].getImage();
    if ((localBufferedImage != null) && (localBufferedImage.getWidth() > 0)) {
      int i = localBufferedImage.getWidth(); int j = localBufferedImage.getHeight();
      float f1 = i / j;
      float f2 = paramInt4 / paramInt5;
      int m;
      int k;
      if (f1 < f2) {
        m = paramInt5;
        k = (int)(i / j * m);
      } else {
        k = paramInt4;
        m = (int)(j / i * k);
      }
      paramGraphics.drawImage(localBufferedImage.getScaledInstance(k, m, 4), paramInt2 + paramInt4 / 2 - k / 2, paramInt3 + paramInt5 / 2 - m / 2, null);
      paramGraphics.setColor(Color.gray);
      paramGraphics.drawRect(paramInt2, paramInt3, paramInt4 - 1, paramInt5 - 1);
    }
  }
}